package com.lxc.service;

import com.lxc.common.PathManagement;
import javax.servlet.http.*;
import java.io.*;
public class FileManagement{
	public FileManagement(){
		musicFilePath = PathManagement.getMusicPath();
		imageFilePath = PathManagement.getImagePath();
	}
    private  String musicFilePath;
    private  String imageFilePath;
    public String saveFile(Part part,String fileName,String tailName){
        if(tailName.equals(".mp3")){
			String targetPath = musicFilePath+"\\"+fileName+tailName;
			try{
            part.write(targetPath);
			}
			catch(IOException e){
				System.out.println("保存音乐失败");
			}
			return targetPath;
        }
        else if(tailName.equals(".jpg")){
			String targetPath = imageFilePath+"\\"+fileName+tailName;
			try{
            part.write(targetPath);
			}
			catch(IOException e){
				System.out.println("保存图片失败");
			}
			return targetPath;
        }
        else{
			return null;
		}
    }
}